package ifrn.pds.siem.banco;

import ifrn.pds.funcoes.User;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Login implements LoginDAO {
	public Banco banco;

	public Login() {
		banco = new Banco();
	}
	
	
	public User efetuarLogin(String usuario, String senha) {
		try {
			User usuarioLogado = null;
			if(!banco.isConnected())
				banco.conectar();
			Statement statement = banco.conexao.createStatement();
			ResultSet rs = statement.executeQuery("select * from usuario where logon = '"+usuario+"' and senha = '"+senha+"'");
			while(rs.next()){
				String user = rs.getString("logon");
				String password = rs.getString("senha");
				String nome = rs.getString("nome"); 
				int permissao = rs.getInt("permissao");
				usuarioLogado = new User(user, password, nome, permissao);
			}
			
			return usuarioLogado;
		} catch (SQLException e) {
			return null;
		}
		
	}
	
}
